package net.wicp.tams.commons.callback.impl.column;

import java.io.UnsupportedEncodingException;

import org.apache.tapestry5.json.JSONObject;

import net.wicp.tams.commons.callback.ICol;

public class ColBytes implements ICol<byte[]> {
	private static final long serialVersionUID = 1L;
	private final byte[] obj;

	public ColBytes(byte[] obj) {
		this.obj = obj;
	}

	@Override
	public String toClient() {
		try {
			return new String(obj, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			return null;
		}
	}

	@Override
	public byte[] toValue() {
		return obj;
	}

	@Override
	public JSONObject toJson(String colName) {
		return new JSONObject(colName, obj);
	}

}
